# coding=utf-8
import re
import sys

if sys.argv[1] == '-h':
        print "format: -<option> -<file>"
        print "options: -h, -l (lexical), -g (cfg)"
        sys.exit(0)

if len(sys.argv) != 3:
        print "Wrong Number of Arguments"
        sys.exit(1)

input_file = open(sys.argv[2]).read()

search_colon = r"::="
replace_colon = r'  :'
input_file = re.sub(search_colon, replace_colon, input_file)

search_for_rules = r"<(.*?)>"
def replace_rules (m):
        rule = m.group(1)
        if sys.argv[1] == '-l':
                rule = '_' + rule.upper()
        rule = rule.replace(" ", '')
        rule = rule.replace("-", '')
        return rule
input_file = re.sub(search_for_rules, replace_rules, input_file)

search_for_strings = r"{(.*?)}"
def replace_strings (m):
        rule = m.group(1)
        if (len(rule) == 1):
                return "'" + rule + "'"
        else:
                return '"' + rule + '"'
input_file = re.sub(search_for_strings, replace_strings, input_file)

print input_file